home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / ipacked.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.6 KB  |  137 lines

  1. /* Copyright (C) 1991, 1992, 1993, 1994, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: ipacked.h,v 1.2 2000/09/19 19:00:46 lpd Exp $ */
  20. /* Packed array format for Ghostscript */
  21.  
  22. #ifndef ipacked_INCLUDED
  23. #  define ipacked_INCLUDED
  24.  
  25. /*
  26.  
  27.    In a packed array, an element may either be a 2-byte ref_packed or a
  28.    full-size ref (8 or 16 bytes).  We carefully arrange the first two bytes,
  29.    which are either an entire ref_packed or the type_attrs member of a ref,
  30.    so that we can distinguish the 2 forms.  The encoding:
  31.  
  32.    00tttttt exrwsfnm    full-size ref
  33.    010mjjjj jjjjjjjj    executable operator (so bind can work)
  34.    011mvvvv vvvvvvvv    integer (biased by packed_min_intval)
  35.    100m---- --------    (not used)
  36.    101m---- --------    (not used)
  37.    110miiii iiiiiiii    literal name
  38.    111miiii iiiiiiii    executable name
  39.  
  40.    The m bit is the mark bit for the garbage collector.
  41.  
  42.    ****** Note for the future: We could get packed tokens into the first-level
  43.    ****** interpreter dispatch by changing to the following representation:
  44.  
  45.    000ttttt exrwsfnm    full-size ref
  46.    m0100jjj jjjjjjjj    executable operator (so bind can work)
  47.    m0101vvv vvvvvvvv    integer (biased by packed_min_intval)
  48.    m011iiii iiiiiiii    literal name
  49.    m100iiii iiiiiiii    executable name
  50.    m101---- --------    (not used)
  51.    m11----- --------    (not used)
  52.  
  53.    ****** We aren't going to do this for a while.
  54.  
  55.    The jjj index of executable operators is either the index of the operator
  56.    in the op_def_table, if the index is less than op_def_count, or the index
  57.    of the definition in the op_array_table (subtracting op_def_count first).
  58.  
  59.    The iii index of names is the one that the name machinery already
  60.    maintains.  A name whose index is larger than will fit in the packed
  61.    representation must be represented as a full-size ref.
  62.  
  63.    There are two packed array types, t_mixedarray and t_shortarray.  A
  64.    t_mixedarray can have a mix of packed and full-size elements; a
  65.    t_shortarray has all packed elements.  The 'size' of a packed array is the
  66.    number of elements, not the number of bytes it occupies.
  67.  
  68.    Packed array elements can be distinguished from full-size elements, so we
  69.    allow the interpreter to simply execute all the different kinds of arrays
  70.    directly.  However, if we really allowed free mixing of packed and
  71.    full-size elements, this could lead to unaligned placement of full-size
  72.    refs; some machines can't handle unaligned accesses of this kind.  To
  73.    guarantee that full-size elements in mixed arrays are always properly
  74.    aligned, if a full-size ref must be aligned at an address which is 0 mod
  75.    N, we convert up to N/2-1 preceding packed elements into full-size
  76.    elements, when creating the array, so that the alignment is preserved.
  77.    The only code this actually affects is in make_packed_array and in the
  78.    code for compacting refs in the garbage collector.
  79.  
  80.    Note that code in zpacked.c and interp.c knows more about the
  81.    representation of packed elements than the definitions in this file would
  82.    imply.  Read the code carefully if you change the representation.
  83.  
  84.  */
  85.  
  86. #define r_packed_type_shift 13
  87. #define r_packed_value_bits 12
  88. typedef enum {
  89.     pt_full_ref = 0,
  90. #define pt_min_packed 2
  91.     pt_executable_operator = 2,
  92.     pt_integer = 3,
  93.     pt_unused1 = 4,
  94.     pt_unused2 = 5,
  95. #define pt_min_name 6
  96.     pt_literal_name = 6,
  97. #define pt_min_exec_name 7
  98.     pt_executable_name = 7
  99. } packed_type;
  100.  
  101. #define packed_per_ref (sizeof(ref) / sizeof(ref_packed))
  102. #define align_packed_per_ref\
  103.   (arch_align_ref_mod / arch_align_short_mod)
  104. #define pt_tag(pt) ((ref_packed)(pt) << r_packed_type_shift)
  105. #define packed_value_mask ((1 << r_packed_value_bits) - 1)
  106. #define packed_max_value packed_value_mask
  107. #define r_is_packed(rp)  (*(const ref_packed *)(rp) >= pt_tag(pt_min_packed))
  108. /* Names */
  109. #define r_packed_is_name(prp) (*(prp) >= pt_tag(pt_min_name))
  110. #define r_packed_is_exec_name(prp) (*(prp) >= pt_tag(pt_min_exec_name))
  111. #define packed_name_max_index packed_max_value
  112. #define packed_name_index(prp) (*(prp) & packed_value_mask)
  113. /* Integers */
  114. #define packed_min_intval (-(1 << (r_packed_value_bits - 1)))
  115. #define packed_max_intval ((1 << (r_packed_value_bits - 1)) - 1)
  116. #define packed_int_mask packed_value_mask
  117.  
  118. /* Packed ref marking */
  119. #define lp_mark_shift 12
  120. #define lp_mark (1 << lp_mark_shift)
  121. #define r_has_pmark(rp) (*(rp) & lp_mark)
  122. #define r_set_pmark(rp) (*(rp) |= lp_mark)
  123. #define r_clear_pmark(rp) (*(rp) &= ~lp_mark)
  124. #define r_store_pmark(rp,pm) (*(rp) = (*(rp) & ~lp_mark) | (pm))
  125.  
  126. /* Advance to the next element in a packed array. */
  127. #define packed_next(prp)\
  128.   (r_is_packed(prp) ? prp + 1 : prp + packed_per_ref)
  129.  
  130. /* Define the current array packing flag (setpacking/currentpacking) */
  131. /* for operators. */
  132. /* This is a ref so that it can be managed properly by save/restore. */
  133. #define ref_array_packing_container i_ctx_p
  134. #define ref_array_packing (ref_array_packing_container->array_packing)
  135.  
  136. #endif /* ipacked_INCLUDED */
  137.